import { LoginResult } from "@/api/login";
import { defineStore } from "pinia";
import { ref,computed } from "vue";

// 创建仓库
export const useMemberStore = defineStore('member',()=>{
  // 会员信息
  const profile=ref<LoginResult>({} as LoginResult)
// 修改会员信息
  const setProfile=(value:LoginResult)=>{
    profile.value=value
  }
// 用户登录状态
  const isLogin=computed(()=>!!profile.value.token) 
  return {profile,setProfile,isLogin}
},
{
  // 配置persist
  // persist:true 相当于 persist:{storage:localStorage}
  persist:{
    // storage:localStorage
    storage:{
      setItem(key,value){
       uni.setStorageSync(key,value)
      },
      getItem(key) {
       return uni.getStorageSync(key)
      }
    }
  }
})

